﻿@model KL.Store.Web.Models.ProductsModel
@using KL.Store.Core;
@{
    var suggestedRowCount = 1;
    var addToCartButtonStyle = 1;
    if (Parameters.Theme == "DK")
    {
        addToCartButtonStyle = 2;
    }
    else if (Parameters.Theme == "WU")
    {
        addToCartButtonStyle = 3;
    }
}
@if (Model != null && Model.RelatedProducts != null && Model.RelatedProducts.Count > 0)
{
    if (Parameters.Theme == "HA" || Parameters.Theme == "WU")
    {
        var itemCounter = 1;
        var columnCount = 1;
        var cssColumnClass = "col-xs-12 col-sm-12 col-md-12 col-lg-12";
        var listImageType = Model.ListImageType;
        listImageType = string.IsNullOrEmpty(listImageType) ? listImageType : "_" + listImageType;
    <div class="dailyOffer">
        <div class="category-main-title">
            <span><b>Fırsat</b> Ürünleri</span>
        </div>
        <div class="standardBorder">
            <div class="products s1@(listImageType)" id="products@(Model.CategoryId)">
                <ul class="suggestedProducts">

                    @foreach (var item in Model.RelatedProducts)
                    {
                        //if (Parameters.Theme == "HA")
                        //{
                        //    item.LinkUrl = "#";
                        //}
                        var inLastColumn = "";
                        if (columnCount != 0 && itemCounter % columnCount == 0)
                        {
                            inLastColumn = "inLastColumn";
                        }
                        else
                        {
                            inLastColumn = "";
                        }
                        <li class="productLi product-block @cssColumnClass @inLastColumn">
                            <div class="product-outer">
                                <div class="product-inner">
                                    <div class="product-image">
                                        <a id="pr_@item.ProductId" class="prdLink" href="@item.LinkUrl" title="@(item.ProductName.Replace("\"", ""))">
                                            @if (item.ProductImageCount > 0)
                                            {
                                                <img id="ip_@item.ProductId" src="@(Parameters.WebSiteImageUrl)/product-medium/@(item.ProductId)_1@(listImageType).jpg" alt="@(item.ProductName.Replace("\"", ""))" />  
                                            }
                                            else
                                            {
                                                <img id="ip_@item.ProductId" src="/Images/@Parameters.Theme/product-image-not-found-200x.jpg" alt="@(item.ProductName.Replace("\"", ""))" />
                                            }
                                        </a>
                                        <a class="incele" href="@item.LinkUrl" title="@(item.ProductName.Replace("\"", ""))">İncele</a>
                                        @if (!item.CheckStock || Parameters.AllowEndedProducts || item.InStockDepo > 0)
                                        {
                                            <a href="@item.LinkUrl">
                                                @if (Parameters.Theme == "HA")
                                                {
                                                    var bottomAbsolute = 10;
                                                    if (item.FastCargo)
                                                    {
                                                        var fastStr = "1-3 Gün Kargo";
                                                        if (item.InStockDepo >= Parameters.MinInStockAmountForFastCargo && Parameters.MinInStockAmountForFastCargo != 0)
                                                        {
                                                            fastStr = "24 Saatte Kargo";
                                                        }
                                                    <div class="productprop prop_24h hidden-xs hidden-sm" style="bottom: @(bottomAbsolute)px;">
                                                        <div class="prop_content">
                                                            <div class="prop_icon"></div>
                                                            <div class="prop_text">
                                                                <div class="prop_text_left"></div>
                                                                <span>@fastStr</span>
                                                            </div>
                                                        </div>
                                                    </div>
                                                        bottomAbsolute += 35;
                                                    }
                                                    else if (item.InStockDepo >= Parameters.MinInStockAmountForFastCargo && Parameters.MinInStockAmountForFastCargo != 0)
                                                    {
                                                    <div class="productprop prop_24h hidden-xs hidden-sm" style="bottom: @(bottomAbsolute)px;">
                                                        <div class="prop_content">
                                                            <div class="prop_icon"></div>
                                                            <div class="prop_text">
                                                                <div class="prop_text_left"></div>
                                                                <span>24 Saatte Kargo</span>
                                                            </div>
                                                        </div>
                                                    </div>
                                                        bottomAbsolute += 35;
                                                    }
                                                    else if (item.DeliveryPeriod == "Gün" && item.DeliveryTime <= Parameters.MinDeliveryTimeForFastCargo && item.DeliveryTime > 0)
                                                    {
                                                    <div class="productprop prop_24h" style="bottom: @(bottomAbsolute)px;">
                                                        <div class="prop_content">
                                                            <div class="prop_icon"></div>
                                                            <div class="prop_text">
                                                                <div class="prop_text_left"></div>
                                                                <span>Hızlı Kargo</span>
                                                            </div>
                                                        </div>
                                                    </div>
                                                        bottomAbsolute += 35;
                                                    }

                                                    if (item.FreeCargo)
                                                    {
                                                    <div class="productprop prop_free hidden-xs hidden-sm" style="bottom: @(bottomAbsolute)px;">
                                                        <div class="prop_content">
                                                            <div class="prop_icon"></div>
                                                            <div class="prop_text">
                                                                <div class="prop_text_left"></div>
                                                                <span>Ücretsiz Kargo</span>
                                                            </div>
                                                        </div>
                                                    </div>
                                                        bottomAbsolute += 35;
                                                    }
                                                    if (item.OpportunityProduct)
                                                    {
                                                    <div class="productprop prop_oppoturnity hidden-xs hidden-sm" style="bottom: @(bottomAbsolute)px;">
                                                        <div class="prop_content">
                                                            <div class="prop_icon"></div>
                                                            <div class="prop_text">
                                                                <div class="prop_text_left"></div>
                                                                <span>Fırsat Ürünü</span>
                                                            </div>
                                                        </div>
                                                    </div>
                                                        bottomAbsolute += 35;
                                                    }
                                                    if (!string.IsNullOrEmpty(item.GiftString))
                                                    {
                                                    <div class="productprop prop_gift" style="bottom: @(bottomAbsolute)px;">
                                                        <div class="prop_content">
                                                            <div class="prop_icon"></div>
                                                            <div class="prop_text">
                                                                <div class="prop_text_left"></div>
                                                                <span>@item.GiftString</span>
                                                            </div>
                                                        </div>
                                                    </div>
                                                    }
                                                    if (item.NewProduct)
                                                    {
                                                    <div class="prop_new hidden-xs hidden-sm"></div>
                                                    }
                                                    if (item.DiscountPercent > 0)
                                                    {
                                                    <div class="prop_discountPercent hidden-xs hidden-sm"><span>%</span>@Convert.ToInt32(item.DiscountPercent)</div>
                                                    }
                                                }

                                                else
                                                {

                                                    var leftAbsolute = 5;
                                                    var bottomAbsolute = 1;
                                                    //var topAbsolute = 190;
                                                    //if (Parameters.Theme == "JB")
                                                    //{
                                                    //    topAbsolute = 246;
                                                    //}
                                                    if (item.FastCargo)
                                                    {
                                                        var fastImg = "Fast";
                                                        var fastStr = "1-3 Gün Kargo";
                                                        if (item.InStockDepo >= Parameters.MinInStockAmountForFastCargo && Parameters.MinInStockAmountForFastCargo != 0)
                                                        {
                                                            fastImg = "24h";
                                                            fastStr = "24 Saatte Kargo";
                                                        }
                                                    <div class="label_fast prod_label" style="left:@(leftAbsolute)px;">
                                                        <img src="/Images/@(Parameters.Theme)/@{@fastImg}.png" alt="@fastStr" />
                                                    </div>
                                                    }
                                                    else if (item.InStockDepo >= Parameters.MinInStockAmountForFastCargo && Parameters.MinInStockAmountForFastCargo != 0)
                                                    {
                                                    <div class="label_fast prod_label" style="left:@(leftAbsolute)px;">
                                                        <img src="/Images/@(Parameters.Theme)/24h.png" alt="24 Satte Kargo" />
                                                    </div>
                                                    }
                                                    else if (item.DeliveryPeriod == "Gün" && item.DeliveryTime <= Parameters.MinDeliveryTimeForFastCargo && item.DeliveryTime > 0)
                                                    {
                                                    <div class="label_fast prod_label" style="left:@(leftAbsolute)px;">
                                                        <img src="/Images/@(Parameters.Theme)/Fast.png" alt="Hızlı Kargo" />
                                                    </div>
                                                    }
                                                    if (item.FreeCargo)
                                                    {
                                                    <div class="label_free prod_label" style="bottom:@(bottomAbsolute)px;">
                                                        <img src="/Images/@(Parameters.Theme)/Free.png" />
                                                    </div>
                                                        bottomAbsolute += 14;
                                                    }
                                                    if (item.OpportunityProduct)
                                                    {
                                                    <div class="label_opportunity prod_label" style="bottom:@(bottomAbsolute)px;">
                                                        <img src="/Images/@(Parameters.Theme)/Opportunity.png" />
                                                    </div>
                                                        bottomAbsolute += 14;
                                                    }
                                                    if (item.NewProduct)
                                                    {
                                                    <div class="label_new prod_label" style="bottom:@(bottomAbsolute)px;">
                                                        <img src="/Images/@(Parameters.Theme)/New.png" />
                                                    </div>
                                                        bottomAbsolute += 14;
                                                    }
                                                    if (item.DiscountPercent > 0)
                                                    {
                                                    <div class="prop_discountPercent"><span>%</span>@Convert.ToInt32(item.DiscountPercent)</div>
                                                    }
                                                    else if (item.DiscountDisplayTotal > 0)
                                                    {
                                                    <div class="prop_discountPercent"><span>%</span>@Convert.ToInt32(item.DiscountDisplayTotal)</div>                                        
                                                    }
                                                }
                                            </a>
                                        }
                                    </div>
                                    <a class="hizliBak" href="#quickViewContainer" title="@(item.ProductName.Replace("\"", ""))" data-id="@item.ProductId" data-name="@item.ProductName" data-prcode="@item.ProductCode" data-imgcount="@item.ProductImageCount"></a>
                                    <div class="product-title">
                                        <a id="pl_@item.ProductId" class="prdLink" href="@item.LinkUrl">@(item.ProductShortName)</a>
                                    </div>
                                    <div class="product-price">
                                        @{
                                        var priceFilterStr = "###,###,##0.00";
                                        if (Parameters.HideOddFromPrice)
                                        {
                                            priceFilterStr = "###,###,##0";
                                        }
                                        var productOldPrice = item.OldPrice > 0 ? @item.OldPrice.ToString("###,###,##0") : "";
                                        var productNewPrice = "";
                                        var productExchangePrice = "";
                                        decimal productNewPriceNumber = 0;
                                        var productSecondPrice = "";
                                        
                                        }
                                        @if (Parameters.ShowExchangePricesWithoutTax && item.ExchangePrice > 0)
                                        {
                                            productExchangePrice = item.ExchangePrice.ToString(priceFilterStr) + " " + item.ExchangeCurrency + " <span class=\"taxinc\">+KDV</span>";
                                        }
                                        @if (Parameters.ShowPricesWithoutTax && item.SpecialPriceWithOutTax > 0)
                                        {
                                            productNewPrice = item.SpecialPriceWithOutTax.ToString(priceFilterStr) + " " + item.Currency + " <span class=\"taxinc\">+KDV</span>";
                                            productNewPriceNumber = item.SpecialPriceWithOutTax;
                                        }
                                        else if (Parameters.ShowPricesWithoutTax && item.SpecialPriceWithOutTax <= 0)
                                        {
                                            productNewPrice = item.PriceWithOutTax.ToString(priceFilterStr) + " " + item.Currency + " </span><span class=\"taxinc\">+KDV</span>";
                                            productNewPriceNumber = item.PriceWithOutTax;
                                        }
                                        else if (!Parameters.ShowPricesWithoutTax && item.SpecialPrice > 0)
                                        {
                                            productNewPrice = item.SpecialPrice.ToString(priceFilterStr) + " " + item.Currency;
                                            productNewPriceNumber = item.SpecialPrice;
                                        }
                                        else if (!Parameters.ShowPricesWithoutTax && item.SpecialPrice <= 0)
                                        {
                                            productNewPrice = item.Price.ToString(priceFilterStr) + " " + item.Currency;
                                            productNewPriceNumber = item.Price;
                                        }
                                        @{
                                        var rate = (item.CampaignProduct && Model.CampaignVoucherRate > 0) ? Model.CampaignVoucherRate : Model.VoucherRate;
                                        if (rate > 0 && !(Parameters.OnlyUseCCandMTforOpportunityProduct && item.OpportunityProduct))
                                        {
                                            productSecondPrice = ((productNewPriceNumber * rate) / (Parameters.ShowVoucherPricesWithInstallment ? Parameters.SenetTaksit1 : 1)).ToString(priceFilterStr) + " " + item.Currency;
                                        }
                                        }
                                        <a href="@item.LinkUrl" class="sale">@if (!item.CheckStock || Parameters.AllowEndedProducts || item.InStockDepo > 0)
                                                                             {
                                                                            
                                            <div class="product-price-section">
                                                @{
                                                    <span class="productNewPriceStr productPrice">@Html.Raw(productNewPrice)</span>
                                                                                 if (!string.IsNullOrEmpty(productExchangePrice))
                                                                                 {
                                                    <span class="productNewPriceStr productPrice">@Html.Raw(productExchangePrice)</span><br />
                                                                                 }
                                                                                 if (productSecondPrice != "")
                                                                                 {
                                                    <span class="productSecondPriceStr"><span class="senetliAyda">@(Parameters.ShowVoucherPricesWithInstallment ? "ayda " : "")</span>@Html.Raw(productSecondPrice)</span>
                                                                                 }
                                                }
                                            </div>
                                    
                                                                                 if (productSecondPrice != "")
                                                                                 {
                                            <div class="product-price-section">
                                                <span class="fiyatAciklama"><span class="fiyatAciklamaSolCizgi">- </span>Kredi Kartı<span class="fiyatAciklamaSagCizgi"> - </span></span>
                                                <span class="fiyatAciklama"><span class="fiyatAciklamaSolCizgi">- </span>Senetli<span class="fiyatAciklamaSagCizgi"> - </span></span>
                                            </div>
                                                                                 }
                                                                                 if (productOldPrice != "")
                                                                                 {
                                            <span class="sale-original">@productOldPrice @item.Currency</span>
                                                                                 }
                                                                                 else if (item.DiscountDisplayTotal > 0)
                                                                                 {
                                                                                     var indirimGoster = ((Decimal.Parse(productNewPrice.Replace(" TL", "")) / (100 - item.DiscountDisplayTotal)) * 100);
                                            <span class="sale-original">@indirimGoster.ToString("###,###,##0") @item.Currency</span>
                                                                                 }
                                                                                 else if (item.MarketPrice > 0)
                                                                                 {
                                            <span class="sale-original">@item.MarketPrice.ToString("###,###,##0") @item.Currency</span>
                                                                                 }
                                                                             }
                                                                             else
                                                                             {
                                            <span style="font-weight: normal;">Tükendi</span>   
                                                                             }
                                        </a>
                                    </div>
                                    @if (Parameters.UseWishList)
                                    {
                                        <div class="toList">
                                            <a id="prd_@item.ProductId" onclick="addToWishList('@(item.ProductId)');" >
                                                <img
                                src="/Images/@(Parameters.Theme)/ToList.jpg" title="Listeme Ekle" alt="Listeme Ekle" style="width: 35px;
                                height: 35px; vertical-align: middle;margin-top:5px" /></a>
                                        </div>
                                    }
                                    @if (!item.CheckStock || Parameters.AllowEndedProducts || item.InStockDepo > 0)
                                    {
                                        if (addToCartButtonStyle == 2)
                                        {<div class="toCart">
                                            <a id="cart_@item.ProductId" @{if (item.InstallmentNeeded)
                                                                           { <text>href="@item.LinkUrl"</text> }
                                                                           else
                                                                           { <text>class="addToCart"</text> }} >
                                                <button class="button-alt">Sepete Ekle</button>
                                            </a>
                                        </div>
                                        }
                                        else if (addToCartButtonStyle == 3)
                                        { 
                                        <div class="hover_block">
                                            <ul class="add-to-links">
                                                <li>
                                                    <a id="cart_@item.ProductId" @{if (item.InstallmentNeeded)
                                                                                   { <text>href="@item.LinkUrl"</text> }
                                                                                   else
                                                                                   { <text>class="addToCart"</text> }} >
                                                        <button type="button" class="button btn-cart">
                                                            <span>
                                                                <span>Sepete Ekle</span>
                                                            </span>
                                                        </button>
                                                    </a>
                                                </li>
                                            </ul>
                                        </div>
                                        }
                                        else
                                        {
                                        <div class="toCart">
                                            <a id="cart_@item.ProductId" @{if (item.InstallmentNeeded)
                                                                           { <text>href="@item.LinkUrl"</text> }
                                                                           else
                                                                           { <text>class="addToCart"</text> }} title="Sepete Ekle">
                                                <img src="/Images/@(Parameters.Theme)/urun-hover-sepet.png" alt="Sepete Ekle" />
                                            </a>
                                        </div>
                                    
                                        }
                                    }

                                    @if (Model.IsManager)
                                    {
                                        <div class="manageProduct">
                                            <a href="/ProductManage/Edit/@(item.ProductId)" class="urunDuzenle fancybox.iframe">
                                                <i class="fa fa-edit fa-2x"></i>
                                            </a>
                                            @if (Model.IsManager)
                                            {
                                                <a href="/Products/RemoveFromCategory/@(Model.CategoryId)/@(item.ProductId)" class="urunSil fancybox.iframe">
                                                    <i class="fa fa-remove fa-2x"></i>
                                                </a>
                                            }
                                        </div>
                                    }
                                </div>
                            </div>
                        </li>
                                    if (itemCounter % columnCount == 0 && itemCounter <= Model.RelatedProducts.Count() - 1)
                                    {
                        @Html.Raw("</ul><ul class=\"suggestedProducts\">");
                                    }
                                    itemCounter++;
                    }
                </ul>
            </div>
            <div class="clearfix"></div>
        </div>
    </div>
                    if (Model.RelatedProducts.Count() > columnCount)
                    {
    <script type="text/javascript">
        $(document).ready(function ()
        {
            if ($(document).width() > 999 && $(".products .suggestedProducts").size() > 1)
            {
                $("#products@(Model.CategoryId)").slidesjs({
                    width: 1000,
                    @{
                        if (columnCount == 6)
                        {
                        <text>height: 175,</text>
                        }
                        else if (columnCount == 4)
                        {
                        <text>height: 205,</text>
                        }
                        else if (columnCount == 3)
                        {
                        <text>height: 260,</text>
                        }
                    }
                    pagination: {
                        active: false
                    },
                    navigation: {
                        active: true,
                        effect: "slide"
                    },
                    play: {
                        active: false,
                        effect: "slide",
                        interval: 5000,
                        auto: true,
                        swap: false,
                        pauseOnHover: true,
                        restartDelay: 5000
                    },
                    pauseOnHover: true
                }).addClass("itWithSlider");
                $("a.slidesjs-navigation").html("");
            }
            else
            {
                var sayyac = 1;
                $("#products@(Model.CategoryId)  ul.suggestedProducts").each(function ()
                {
                    if (sayyac == 1)
                    {
                        $(this).addClass("mainSuggestedList");
                    }
                    else
                    {
                        $(".mainSuggestedList").append($(this).html());
                        $(this).remove();
                    }
                    sayyac++;
                });
                $("ul.suggestedProducts").find("li.inLastColumn").removeClass("inLastColumn");
                var liSayac = 1;
                $("ul.suggestedProducts").find("li").each(function ()
                {
                    if (liSayac % 2 == 0)
                    {
                        $(this).addClass("inLastColumn");
                    }
                    liSayac++;
                });
            }
        });
    </script>
                    }
    }
    else
    {
    <div class="suggested-products">
        <div class="suggested-products-row">
            <div class="suggested-products-inner">
                <div class="suggested-products-content">
                    <div class="suggested-products-slider">
                        <div class="suggested-section">
                            <ul>
                                @{var suggestedPriceCount = 1;}
                                @foreach (var item in Model.RelatedProducts)
                                {
                                    <li>
                                        <a href="#quickViewContainer" class="hizliBak" rel="nofollow"  data-id="@item.ProductId" data-name="@item.ProductName" data-prcode="@item.ProductCode" data-imgcount="@item.ProductImageCount">
                                            @if (item.ProductImageCount > 0)
                                            {
                                                <img id="sbpi_@item.ProductId" src="@(Parameters.WebSiteImageUrl)/product-medium/@(item.ProductId)_1_s.jpg" alt="@(item.ProductName.Replace("\"", ""))" />
                                            }
                                            else
                                            {
                                                <img id="sbpi_@item.ProductId" src="/Images/@Parameters.Theme/product-image-not-found-200x.jpg" alt="@(item.ProductName.Replace("\"", ""))" />
                                            }
                                            <p class="product-name"><span>@item.ProductName</span></p>
                                            @{
                                            var readPrice = "";
                                            if (item.SpecialPrice > 0)
                                            {
                                                readPrice = item.SpecialPrice.ToString("###,###,##0.00") + " " + item.Currency;
                                            }
                                            else
                                            {
                                                readPrice = item.Price.ToString("###,###,##0.00") + " " + item.Currency;
                                            }                                       
                                            }
                                            <p class="product-price">@readPrice</p>
                                        </a>
                                        @if (Model.IsManager)
                                        {
                                            <div class="manageProduct">
                                                <a href="/ProductManage/Edit/@(item.ProductId)" class="urunDuzenle fancybox.iframe">
                                                    <i class="fa fa-edit fa-2x"></i>
                                                </a>
                                                <a href="/Products/RemoveFromCategory/@(Model.CategoryId)/@(item.ProductId)" class="urunEkle fancybox.iframe">
                                                    <i class="fa fa-remove fa-2x"></i>
                                                </a>
                                            </div>
                                        }
                                    </li>
                                        if (suggestedPriceCount % suggestedRowCount == 0)
                                        {
                                    @(new HtmlString("</ul></div><div class=\"suggested-section\"><ul>"))
                                        }
                                        suggestedPriceCount++;
                                }
                            </ul>
                        </div>
                    </div>
                    <script type="text/javascript">
                        $(window).load(function ()
                        {
                            if ($(document).width() > 999 && $(".suggested-products-slider .suggested-section").size() > 1)
                            {
                                $(".suggested-products-slider").slidesjs({
                                    width: 100,
                                    height: 835,
                                    pagination: {
                                        active: false
                                    },
                                    navigation: {
                                        active: true,
                                        // [boolean] Generates next and previous buttons.
                                        // You can set to false and use your own buttons.
                                        // User defined buttons must have the following:
                                        // previous button: class="slidesjs-previous slidesjs-navigation"
                                        // next button: class="slidesjs-next slidesjs-navigation"
                                        effect: "slide"
                                        // [string] Can be either "slide" or "fade".
                                    },
                                    play: {
                                        active: true,
                                        // [boolean] Generate the play and stop buttons.
                                        // You cannot use your own buttons. Sorry.
                                        effect: "slide",
                                        // [string] Can be either "slide" or "fade".
                                        interval: 5000,
                                        // [number] Time spent on each slide in milliseconds.
                                        auto: true,
                                        // [boolean] Start playing the slideshow on load.
                                        swap: false,
                                        // [boolean] show/hide stop and play buttons
                                        pauseOnHover: true,
                                        // [boolean] pause a playing slideshow on hover
                                        restartDelay: 4500
                                        // [number] restart delay on inactive slideshow
                                    }
                                });
                                $("a.slidesjs-navigation").html("");
                                /*$('.suggested-products-slider').bxSlider({
                                    mode: 'horizontal',
                                    pager: false,
                                    controls: true,
                                    infiniteLoop: true,
                                    auto: true,
                                    pause: 3000,
                                    autoStart: true,
                                });*/
                            }
                        });
                    </script>
                </div>
            </div>
            <div class="clearfix"></div>
        </div>
        <div class="suggested-products-title">Önerdiklerimiz</div>
    </div>
    }
}
@if (Model.IsManager)
{
    <div style="display: block; height: 36px; position: relative; width: 100%;">
        <a href="/Products/AddProductToCategory/@(Model.CategoryId)" class="urunSil fancybox.iframe edit-genel">
            <i class="fa fa-link fa-2x"></i>
        </a>
    </div>
}